import QtQuick 2.7
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12

Button {
    height: 48
    width: 48
    background: Item {
        anchors.fill: parent
    }
    icon {
        source: "qrc:/images/phone.png"
        height: 48
        width: 48
        color: "white"
    }
    spacing: 0
    padding: 0
    display: AbstractButton.IconOnly

    onClicked: {
        callPopup.open()
    }
    Popup {
        height: 300
        width: 500
        id: callPopup
        padding: 0

        anchors.centerIn: Overlay.overlay
        Rectangle {

            height: 64
            width: parent.width
            color: "green"
            id:recTitle
            Text {
                text: qsTr("视频通话");
                anchors.left: parent.left
                font.pixelSize: 20
                anchors.verticalCenter: parent.verticalCenter
                anchors.margins: 12;

            }
            Button {
                height: parent.height
                width: 48
                icon {
                    source: "qrc:images/close_face.png"
                    color: "white"
                }
                background: Item{

                }
                anchors.right: parent.right
                onClicked: {
                     callPopup.close()
                }
            }
        }
        ListView {
            width: parent.width
            anchors.bottom: parent.bottom
            anchors.top: recTitle.bottom

            delegate: Rectangle {
                    border.width: 1

                    border.color: "#999999"
                    width: parent.width
                    height: 48
                    Text {
                    anchors.margins: 20
                    anchors.left:parent.left
                    anchors.verticalCenter: parent.verticalCenter
                    text: qsTr(modelData)
                    font.pixelSize: 16
                                        }
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            pntext.peername = modelData;
                            //recTitle.color = "#274d00"
                            calldialog.open()
                            //console.log("mdata: ", modelData)
                        }
                    }

                }
            Popup {
                id: calldialog
                dim: true
                parent: Overlay.overlay
                height: 238
                width: 500
                padding: 0
                anchors.centerIn: parent
                background: Rectangle {

                }
                ColumnLayout {
                    Layout.fillHeight: true
                    width: parent.width
                    Rectangle {
                        height: 64
                        Layout.fillWidth: true
                        Text {
                            anchors.left: parent.left
                            anchors.top: parent.top
                            text: qsTr("视频通话")
                            anchors.margins: 16
                            font.pixelSize: 24
                            color: "white"
                        }
                        color: "green"
                    }
                    Rectangle {
                        Layout.fillWidth: true
                        height: 100
                        Text {
                            id: pntext
                            property string  peername
                            text: qsTr("即将和")+qsTr(peername)+qsTr("视频通话")
                            font.pixelSize: 20
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.margins: 20
                            anchors.left: parent.left
                        }
                    }

                    RowLayout {
                        height: 64
                        Layout.fillWidth: true
                        Button {
                            Layout.fillHeight: true
                            Layout.margins: 20
                            width: 48
                            text: qsTr("取消")
                            onClicked: {
                                calldialog.close()

                            }

                        }
                        Item {
                            Layout.fillWidth: true
                        }
                        Button {
                            text: qsTr("确定")
                            Layout.margins: 20
                            onClicked: {

                                callframe.open()
                            }

                        }
                    }


                }

            }

            Popup {
                id: callframe
                onOpened: {
                    callPopup.close()
                    calldialog.close()
                }
                parent: Overlay.overlay
                height: 400
                width: 500
                padding: 0
                anchors.centerIn: parent
                background: Rectangle {

                }
                ColumnLayout {
                    height: parent.height
                    width: parent.width
                    Button {
                        implicitHeight:  128
                        implicitWidth: 128
                        Layout.margins: 20
                        icon{
                            height: 64
                            width: 128
                            source:  "qrc:/images/user2.png"
                        }
                        Layout.alignment: Qt.AlignHCenter | Qt.AlignTop

                    }
                    Text {
                        Layout.alignment: Qt.AlignHCenter
                        text:  pntext.peername
                    }
                    Item {
                        Layout.fillHeight: true

                    }
                    Text {
                        Layout.alignment: Qt.AlignCenter | Qt.AlignTop
                        text: qsTr("等待对方接受邀请......")
                        font.pixelSize: 20;
                    }
                    Item {
                        Layout.fillHeight: true

                    }
                    Button {
                        Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
                        Layout.margins: 20
                        contentItem: Text {
                            text: qsTr("取消")
                            font.pixelSize: 24;

                        }
                        background: Rectangle {
                            color: "red"
                        }
                        onClicked: {
                            callframe.close()
                        }
                    }
                }

            }

            Component.onCompleted: {
                model = Services.getLibRoomNames()
            }
        }
    }
}


